// packageB/pages/package/smart_box/search/self/index.js
const mybehavior = require("../../../../../../behaviors/requests")
Page({

    /**
     * 页面的初始数据
     */
    behaviors: [mybehavior],
    data: {
        baseUrl: "https://logisticsengineering.gree.com/smartg_api/material_manage",
        button_style1: "button_style1_selected",
        button_style2: "button_style2",
        daiqu_flag: true,
        yiqu_flag: false,
        data_list: [],
        data_list_yiqu: [



        ],
        page: 1,
        pagesize: 3,
        parameter: "",
        total: 0,

    },
    showCode(e) {
        console.log(e);
        wx.showModal({
            title: '',
            content: '取件码：' + e.currentTarget.dataset.row.pickup_code,
            showCancel: false,
            confirmText: "关闭",
            complete: (res) => {
                if (res.cancel) {

                }

                if (res.confirm) {

                }
            }
        })
    },
    getDatasSearch() {
        if (this.data.parameter) {
            this.setData({
                data_list: [],
                page: 1,
                pagesize: 3,
                total: 0
            })
            this.getDatas()
        } else {
            wx.showToast({
                title: '请输入关键字查询！',
                icon: 'none'
            })
            this.setData({
                data_list: [],
                page: 1,
                pagesize: 3,
                total: 0
            })
        }

    },
    // 代领查询数据
    getDatas() {
        let url = this.data.baseUrl + "/get_materials_of_others"
        let data = {
            page: this.data.page,
            pagesize: this.data.pagesize,
            parameter: this.data.parameter,
        }
        this.post(url, data).then(res => {

            if (res.code == 20000) {
                let array = res.data.results
                let arr_list = []
                arr_list = this.data.data_list.concat(array)
                this.setData({
                    data_list: arr_list,
                    total: res.data.total
                })

                wx.hideLoading()
            } else {
                wx.showToast({
                    title: res.msg,
                    icon: 'none'
                })
            }
        }).catch(err => {
            this.setData({
                data_list: [],
                total: 0
            })
            wx.showToast({
                title: err.msg,
                icon: 'none'
            })
        })


    },


    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        // this.getDatas()
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {
        wx.showLoading({
            title: '加载中..'
        })
        const e = this.data.page + 1
        if (Math.ceil(this.data.total / this.data.pagesize) >= e) {
            this.setData({
                page: e
            })
            this.getDatas(e)
        } else {
            wx.showToast({
                title: '已经到底啦~',
                icon: 'none'
            })
        }


    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})